﻿//==============================================================================================
//Author: Uncle Song
//Create Date: 2022-06-20
//Description: 图片扩展方法
//----------------------------------------------------------------------------------------------
//Alter History:
//              2022-06-20  add 热力图创建.
//              2022-06-21  remove 热力图创建.
//============================================================================================== 
using System.Collections.Generic;
using UnityEngine;

namespace FrameWorkSong
{
    public static class Texture2DExtention
    {
        //public static void CreatHeatMap(this Texture2D texture,  List<HeatMapInfo> heatMapInfos, HeatMapBase heatMapBase)
        //{
             
        //    List<Vector2> my_Pixels = new List<Vector2>();
        //    List<float> my_Values = new List<float>();
        //    for (int y = 0; y < texture.height; y++)
        //    {
        //        for (int x = 0; x < texture.width; x++)
        //        {

        //            Vector2 pixel = new Vector2(x, y);
        //            my_Pixels.Add(pixel);
        //            my_Values.Add(0);
        //        }
        //    }
        //    int allLength = my_Pixels.Count;//所以像素点数量
        //    int pointLength = heatMapInfos.Count;//热力图兴趣点点数量
        //    int colorLength = heatMapBase.HeatMapInfos.Count;//色块等级
        //    for (int p = 0; p < pointLength; p++)
        //    {
        //        for (int a = 0; a < allLength; a++)
        //        {
        //            float my_Distance = Vector2.Distance(heatMapInfos[p].Pixel, my_Pixels[a]);
          
        //            float my_MaxDis = heatMapBase.DisRatio * heatMapInfos[p].Amount;
                  
        //            if (my_Distance < my_MaxDis)
        //            {
                        
        //                float value = (1 - (Mathf.Pow(my_Distance, 2) / Mathf.Pow(my_MaxDis, 2))) * heatMapInfos[p].Amount;
        //               // Debug.Log("value=" + value );
        //                if (value > my_Values[a])
        //                {
        //                    my_Values[a] = value;
        //                }
        //            }
        //        }
        //    }
        //    for (int i = 0; i < allLength; i++)
        //    {
        //        for (int j = 0; j < colorLength; j++)
        //        {
        //            if (my_Values[i] >= heatMapBase.HeatMapInfos[j].MaxAmount)
        //            {
        //                if (j!=0)
        //                {
        //                    float t = (my_Values[i] - heatMapBase.HeatMapInfos[j].MaxAmount) / (heatMapBase.HeatMapInfos[j - 1].MaxAmount - heatMapBase.HeatMapInfos[j].MaxAmount);
        //                    texture.SetPixel((int)my_Pixels[i].x, (int)my_Pixels[i].y, Color.Lerp(heatMapBase.HeatMapInfos[j].Color, heatMapBase.HeatMapInfos[j - 1].Color, t));
        //                    break;
        //                }
        //                else
        //                {
        //                    texture.SetPixel((int)my_Pixels[i].x, (int)my_Pixels[i].y, heatMapBase.HeatMapInfos[j].Color);
        //                    break;
        //                }

                    
        //            }
        //        }
        //    }
        //    texture.Apply();
        //}
    }
}
